import numpy as np
import matplotlib.pyplot as plt
import torch
import seaborn as sns

def f(x):
    return torch.pow((x-2.0),2)

def fP(x):
    return 2 * x -4

x_axis_vals = np.linspace(-7,9,100)
y_axis_vals = f(torch.tensor(x_axis_vals)).numpy()
# sns.lineplot(x=x_axis_vals,y=y_axis_vals,label='$f(x)=(x-2)^2$')
y_axis_vals_p = fP(torch.tensor(x_axis_vals)).numpy()
sns.lineplot(x=x_axis_vals,y=[0.0] * len(x_axis_vals),label='0',color='black')
sns.lineplot(x=x_axis_vals,y=y_axis_vals,label='Function to Minimize$f(x)=(x-2)^2$')
sns.lineplot(x=x_axis_vals,y=y_axis_vals_p,label='Gradient of the function $f(x)=2*x - 4 $')
plt.show()